/**
 * Matrix2.java
 * 
 * @date: 2012-02-28
 * @author: Xiaoyu Guo (MUN# 200982155)
 * This file is part of the course project for COMP 6752, 
 * Application of Computer Graphics. All the file is written
 * by myself.
 */
package mun.cs6752.project.model;

/** Matrix2 defines a 2x2 matrix.
 * 2x2 matrices are commonly used in 2D transformation.
 * @author Xiaoyu Guo
 */
public class Matrix2 extends Matrix {
    private static final int SIZE = 2;
    
    /**
     * @param source
     */
    public Matrix2(double[][] source) {
        super(source);
        
        if(width != SIZE || height != SIZE){
            throw new IllegalArgumentException("matrix must be 2x2");
        }
    }

    public Matrix2(){
        super(SIZE, SIZE);
    }
    
    public Matrix2(double a11, double a12, double a21, double a22){
        super(SIZE, SIZE);
        setA11(a11);
        setA12(a12);
        setA21(a21);
        setA22(a22);
    }
    
    public double getA11(){
        return get(0, 0);
    }
    
    public double getA12(){
        return get(0, 1);
    }
    
    public double getA21(){
        return get(1, 0);
    }
    
    public double getA22(){
        return get(1, 1);
    }
    
    public void setA11(double value){
        set(0, 0, value);
    }
    
    public void setA12(double value){
        set(0, 1, value);
    }
    
    public void setA21(double value){
        set(1, 0, value);
    }
    
    public void setA22(double value){
        set(1, 1, value);
    }
    
    public Vector2 multiply(Vector2 value){
        Vector result = super.multiply(value);
        return new Vector2(result);
    }
}
